import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n
import '@/styles/index.scss' // global css
import './icons/icons.css'
import './icons/font.css'
import './icons/icons'
import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control
import '@/styles/output.css'

import Debounce from '@/utils/antishake.js'


let img = require('./assets/images/appEooro.png')

Vue.use(ElementUI)

Vue.component('Debounce', Debounce)

Vue.filter('newDate', function (value) {
  if (value == '未登录' || value == '') return value
  if (value === null) return '无'
  if (value === undefined) return '-'
  let date = new Date(parseInt(value) * 1000);
  let y = date.getFullYear();
  let m = (date.getMonth() + 1 + '').padStart(2, '');
  let d = (date.getDate() + '').padStart(2, '0');
  let h = date.getHours();
  let minute = date.getMinutes();
  let second = date.getSeconds();
  minute = minute < 10 ? "0" + minute : minute;
  second = second < 10 ? "0" + second : second;
  return `${y}-${m}-${d} ${h}:${minute}:${second}`
})

Vue.filter('imgErr', function (value) {
  var Img = new Image();
  Img.src = value;
  if (Img.fileSize > 0 || (Img.width > 0 && Img.height > 0)) {
    return Img.src
  } else {
    return img
  }
})

Vue.filter('numberDays', function (value) {
  if (value === null) return '无'
  let date = new Date(parseInt(value) * 1000);
  let y = date.getFullYear();
  let m = (date.getMonth() + 1 + '').padStart(2, '');
  let d = (date.getDate() + '').padStart(2, '0');
  let h = date.getHours();
  let minute = date.getMinutes();
  let second = date.getSeconds();
  minute = minute < 10 ? "0" + minute : minute;
  second = second < 10 ? "0" + second : second;
  return `${y}-${m}-${d}`
})

Vue.filter('activationTime', function (value) {
  if (value === null || value == 0) return '未激活'
  let date = new Date(parseInt(value) * 1000);
  let y = date.getFullYear();
  let m = (date.getMonth() + 1 + '').padStart(2, '');
  let d = (date.getDate() + '').padStart(2, '0');
  let h = date.getHours();
  let minute = date.getMinutes();
  let second = date.getSeconds();
  minute = minute < 10 ? "0" + minute : minute;
  second = second < 10 ? "0" + second : second;
  return `${y}-${m}-${d}`
})

Vue.filter('activateTime', function (value) {
  if (value === null) return '无'
  if (value === 0) return '未激活'
  let date = new Date(parseInt(value) * 1000);
  let y = date.getFullYear();
  let m = (date.getMonth() + 1 + '').padStart(2, '');
  let d = (date.getDate() + '').padStart(2, '0');
  let h = date.getHours();
  let minute = date.getMinutes();
  let second = date.getSeconds();
  minute = minute < 10 ? "0" + minute : minute;
  second = second < 10 ? "0" + second : second;
  return `${y}年${m}月${d}日`
})

Vue.filter('zhDate', function (size) {
  if (!size) return "";
  var num = 1024.00; //byte
  if (size < num) return size + "B";
  if (size < Math.pow(num, 2)) return (size / num).toFixed(2) + "KB"; //kb
  if (size < Math.pow(num, 3)) return (size / Math.pow(num, 2)).toFixed(2) + "MB"; //M
  if (size < Math.pow(num, 4)) return (size / Math.pow(num, 3)).toFixed(2) + "G"; //G
  return (size / Math.pow(num, 4)).toFixed(2) + "T"; //T
})

Vue.filter('getFlow', function (value) {
  var flow = "";
  //value = value * 1024
  console.log('打消', value)
  //如果赠送流量小于1MB.则显示为KB
  if (value / 1024 < 1024) {
    flow = (Math.round(value / 1024) > 0 ? Math.round(value / 1024) : 0) + 'KB';
  } else if (value / 1024 >= 1024 && value / 1024 / 1024 < 1024) {
    //如果赠送流量大于1MB且小于1GB的则显示为MB
    flow = (Math.round(value / 1024 / 1024) > 0 ? Math.round(value / 1024 / 1024) : 0) + 'MB';
  } else if (value / 1024 / 1024 >= 1024) {
    //如果流量大于1Gb
    var gb_Flow = value / 1024 / 1024 / 1024;
    //toFixed(1);四舍五入保留一位小数
    flow = gb_Flow.toFixed(1) + 'GB';
  } else {
    flow = "0KB";
  }
  return flow;
})

Vue.config.productionTip = false
Vue.prototype.SunloginControl = window.SunloginControl

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
